<template>
  <div>
    <el-dialog title="筛选结果" :visible.sync="dialogVisible" :close-on-click-modal="false" :before-close="closeDialog" v-on:open="loadData">
      <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-form">
        <el-form-item label="筛选号" style="">
          <span v-text="form.num" :readonly="form.num!=undefined||form.num==null"></span>
        </el-form-item>
        <el-form-item label="筛选结果" style="width: 100%">
          <el-radio class="radio" v-model="form.candidateResult" :label="1">成功</el-radio>
          <el-radio class="radio" v-model="form.candidateResult" :label="3">补位</el-radio>
          <el-radio class="radio" v-model="form.candidateResult" :label="2">失败</el-radio>
        </el-form-item>
        <el-form-item label="失败原因" style="width: 100%" v-if="form.candidateResult==2">
          <el-input v-model="form.nopassRemark" type="textarea"></el-input>
        </el-form-item>
        <!--<el-form-item label="受试者号" style="" v-if="form.candidateResult">-->
          <!--<el-input v-model="form.num"></el-input>-->
        <!--</el-form-item>-->
        <!-- <el-form-item label="随机号" style="" v-if="form.candidateResult==1||form.candidateResult==3">
          <el-input v-model="form.randomNum"></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="服药" style="width: 100%">
          <el-radio class="radio" v-model="form.medicine" :label="1">R</el-radio>
          <el-radio class="radio" v-model="form.medicine" :label="2">T</el-radio>
        </el-form-item> -->
        <el-form-item class="button-row">
          <el-button v-if="$utils.ckUIPower('S01010101')" type="primary" @click.native.prevent="handleSubmit" :disabled="editClick">确定
          </el-button>
          <el-button @click.native.prevent="closeDialog">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  import http from '../../../api/http'
  var model = {
    num: '',
    randomNum: '',
    nopassRemark: '',
    candidateResult:1,
    //medicine:1,
    id:'',
    projectId:''
  };
  export default {
    data () {
      return {
        editClick:false,
        title: '筛选结果', form: Object.assign({}, model),
        rules: {
        },
        addBtnTxt: ''
      }
    },
    props: {
      resultDialogVisible: {
        type: Boolean,
        default: false
      },
      id: {
        type:String
      },
      num:{
          type:String
      }
    },
    computed: {
      dialogVisible: {
        get: function () {
          return this.resultDialogVisible
        },
        set: function () {}
      }
    },
    methods: {
      handleReset () {
        this.$refs.form.resetFields()
      },
      handleSubmit (ev) {
        var vm = this;
        this.$refs.form.validate(function (valid) {
          if (valid) {
              if(vm.form.candidateResult=="1"||vm.form.candidateResult=="3"){
                  //    if(vm.form.randomNum==""){
                  //       vm.$message({
                  //         type: 'warning',
                  //         message: '请填写随机号!'
                  //       });
                  //     return;
                  // }
                }else{
                  if(vm.form.nopassRemark==""){
                    vm.$message({
                          type: 'warning',
                          message: '请填写失败原因!'
                        });
                      return;
                  }
                }
            vm.form.projectId =vm.$utils.getCurrenrProject().id;
              vm.editClick = true;
              http.postData(vm, "/pt/candidateSubjects/changeActiveResult", {json: JSON.stringify(vm.form)}, function (resp) {
              var ret = resp.body;
              if (ret.code === '111') {
                vm.$notify({title: '操作提示', message: ret.msg, type: 'success'});
                vm.form = Object.assign({}, model);
                vm.$parent.closeResultDialog(ret.value);
                vm.closeDialog();
                vm.$parent.closeDialog();
                vm.$parent.$parent.onSubmit();
                // vm.$parent.onSubmit();
                // vm.$parent.onSubmit();
              } else {
                vm.editClick = false;
                vm.$notify.error({title: '操作失败', message: ret.msg});
              }
            });
          } else {
            return false
          }
        })
      },
      closeDialog(){
        this.form.nopassRemark ='';
        this.editClick = false;
        this.$parent.closeResultDialog();
        // this.$parent.closeDialog();

      },
      loadData(){
        var vm = this;
        vm.form.id = vm.id;
        
        vm.form.randomNum ='';
        http.postData(vm, "/pt/candidateSubjects/getCanNum", {id:vm.form.id}, function (resp) {
              var ret = resp.body;
              console.log(resp)
              if (ret.code === '111') {
                vm.form.num = ret.value;
              } else {
                
              }
            });
      }
    }
  }
</script>
